#!/bin/bash
# Script to join a peer to a channel
{% include "envsetting.j2" %}
if [ ! -f "{{ CHANNEL_NAME }}.genesis.block" ]; then
  peer channel fetch oldest -o $ORDERER_ADDRESS --cafile $ORDERER_TLS_CA \
  --tls -c {{ CHANNEL_NAME }} /vars/{{ CHANNEL_NAME}}.genesis.block
fi

peer channel join -b /vars/{{ CHANNEL_NAME }}.genesis.block \
  -o $ORDERER_ADDRESS --cafile $ORDERER_TLS_CA --tls
